class Swarm < ActiveRecord::Base
  belongs_to :catelog
  has_many :user_connections,
           :conditions=>["thetime > :thetime",{:thetime=>6.minutes.ago}]
  def self.save(swarm,new_url,pic_url)
    t=Time.new
    
    if !swarm[:pic_url].nil?
      filename=(pic_url)+"_"+swarm[:pic_url].original_filename.gsub(/^.*(\\|\/)/, '')
      File.open("./public/images/kerjodando_pic/"+filename,"wb"){|f|f.write(swarm[:pic_url].read)}
    else
      filename=""
    end
    swarm[:pic_url]=filename
    swarm[:creation_time]=t
    swarm[:url]=new_url
    Swarm.new(swarm).save
  end
  
end
